package com.example.login.Service;

import com.example.login.Mapper.GoodsMap;
import com.example.login.Mapper.MP3Map;
import com.example.login.Mapper.MobilePhoneMap;
import com.example.login.Mapper.PCMap;
import com.example.login.Pojo.MP3;
import com.example.login.Pojo.MobilePhone;
import com.example.login.Pojo.PC;
import com.example.login.Pojo.mp3Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ItemService")
public class ItemService {
    @Autowired
    GoodsMap goodsMap;
    @Autowired
    MobilePhoneMap mobilePhoneMap;
    @Autowired
    PCMap pcMap;
    @Autowired
    MP3Map mp3Map;
    public List<mp3Goods> getMp3Goods()
    {
        return goodsMap.getMp3Goods();
    }

    public Object getItem(int id,String sku_code)
    {
        String cid=goodsMap.determine(id);
        switch (cid)
        {
            case "MobilePhone":
                return goodsMap.getMobileGood(id,sku_code);
            case "MP3":
                return goodsMap.getMp3Good(id,sku_code);
            case "PC":
                return goodsMap.getPCGood(id,sku_code);
            default:
                return null;
        }
    }
    //删除商品

    public void delete(int id,String sku_code){
        String cid=goodsMap.determine(id);
        switch (cid){
            case "MobilePhone":
                mobilePhoneMap.DeleteMobilePhone(id,sku_code);
                List<MobilePhone> mobilePhone=mobilePhoneMap.getMobilePhoneById(id);
                if(mobilePhone.size()==0)
                    goodsMap.delete(id);
                break;
            case "MP3":
                mp3Map.DeleteMP3(id, sku_code);
                List<MP3> mp3=mp3Map.getMP3ById(id);
                if(mp3.size()==0)
                    goodsMap.delete(id);
                break;
            case "PC":
                pcMap.DeletePC(id, sku_code);
                List<PC> pc=pcMap.getPCById(id);
                if(pc.size()==0)
                    goodsMap.delete(id);
                break;
        }
    }

    //修改信息
    public void UpdateInformation(int id,String sku_code,int price,int num,int fright,String combination,String introduction,String image){
        String cid=goodsMap.determine(id);
        goodsMap.ModifyPrice(id,fright);
        switch (cid){
            case "MobilePhone":
                mobilePhoneMap.UpdateMobilePhone(id,sku_code,price,num,combination,introduction,image);
                break;
            case "MP3":
                mp3Map.UpdateMp3(id,sku_code,price,num,combination,introduction,image);
                break;
            case "PC":
                pcMap.UpdatePC(id,sku_code,price,num,combination,introduction,image);
                break;
        }

    }

    //上下架改动
    public void update(int id,String sku_code){
        String cid=goodsMap.determine(id);
        switch (cid){
            case "MobilePhone":
                if(goodsMap.DetermineMoibleStatus(id,sku_code).getStatus()==0)
                    goodsMap.MobileOffShelf(id,sku_code,1);
                else goodsMap.MobileOffShelf(id,sku_code,0);
                break;
            case "MP3":
                if(goodsMap.DetermineMp3Status(id,sku_code).getStatus()==0)
                    goodsMap.Mp3OffShelf(id,sku_code,1);
                else goodsMap.Mp3OffShelf(id,sku_code,0);
                break;
            case "PC":
                if(goodsMap.DeterminePcStatus(id, sku_code).getStatus()==0)
                    goodsMap.PcOffShelf(id,sku_code,1);
                else goodsMap.PcOffShelf(id,sku_code,0);
                break;
        }

    }
}
